package com.yjd.bi.statistic.control;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yjd.bi.comm.utils.BiDateUtil;
import com.yjd.bi.report.enums.StatisticsTypeEnum;
import com.yjd.bi.report.enums.TimeType;
import com.yjd.bi.report.model.EChartsModel;
import com.yjd.bi.user.service.IUserStatisticsConditionService;
import com.yjd.comm.annotation.ServiceRemoteProxy;
import com.yjd.comm.base.control.BaseControl;
import com.yjd.comm.rpm.RpmServiceKeyEnum;
import com.yjd.comm.util.DateUtil;
import com.yjd.comm.util.FrameUtil;

@Controller
@Scope("prototype")
@RequestMapping("/age/")
public class AgeControl extends BaseControl {


    @ServiceRemoteProxy(serviceUrlResouceKey = RpmServiceKeyEnum.RPM_BI_SERVICE_KEY)
    private IUserStatisticsConditionService userStatisticsConditionService;

    @RequestMapping("index")
    public String deal() throws Exception {
        request.setAttribute("start", "2013-12-21");
        request.setAttribute("now", BiDateUtil.initBiDate());
        return "age.index";
	}

	/**
	 * 查询年龄相关数据统计
	 * @param timeType
	 * @param timeFrom
	 * @throws Exception
	 */
	@RequestMapping("getDatasByField")
	public void getDatasByField(String queryType) throws Exception{
		StatisticsTypeEnum statisticsType=StatisticsTypeEnum.getStatisticsType(queryType);
		EChartsModel ec=this.userStatisticsConditionService.getUserNumByAge(statisticsType);
		this.successData(FrameUtil.newHashMap("option",ec));
	}

    /**
     * 根据yyyy-MM-dd转为long格式的yyyyMMdd
	 * @return
	 */
	public String getTime(String time){
		return DateUtil.timestampToDateString(DateUtil.dateStringToTimestamp(time, DateUtil.PATTERN_yyyy_MM_dd), DateUtil.PATTERN_yyyyMMdd);
	}
}
